<?php
global $_GPC, $_W;
$GLOBALS['frames'] = $this->getMainMenu();

load()->func('tpl');
$pageindex = max(1, intval($_GPC['page']));
$pagesize=10;
// $where=' WHERE  uniacid=:uniacid  ';
// $data[':uniacid']=$_W['uniacid'];
// $sql="SELECT * FROM ".tablename('zh_yjm_store') .$where." ORDER BY sort desc";
// $total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_yjm_store').$where." ORDER BY sort desc",$data);
$where=' WHERE  a.uniacid=:uniacid  ';
$data[':uniacid']=$_W['uniacid'];
$sql="SELECT a.*,b.title as storetype FROM ".tablename('zh_yjm_store'). " a left join ". tablename("zh_yjm_storetype")." b on a.storetype_id=b.id " .$where." ORDER BY a.sort desc";
$total=pdo_fetchcolumn("SELECT count(*) FROM ".tablename('zh_yjm_store'). " a left join ". tablename("zh_yjm_storetype")." b on a.storetype_id=b.id ".$where." ORDER BY a.sort desc",$data);

$select_sql =$sql." LIMIT " .($pageindex - 1) * $pagesize.",".$pagesize;
$store=pdo_fetchall($select_sql,$data);
$pager = pagination($total, $pageindex, $pagesize);

// $store = pdo_fetchall("SELECT * FROM " . tablename('zh_yjm_store'). "  WHERE uniacid = ".$_W['uniacid']. "  ORDER BY sort DESC");
// for ($i=0; $i <count($store) ; $i++) { 
// 	$store[$i]['storetypes']=pdo_get('zh_yjm_storetype',array('id'=>$store[$i]['storetype_id']));
// 	$store[$i]['storetype']=$store[$i]['storetypes']['title'];
// }

$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if($op=='delete'){
	$user=pdo_get('zh_yjm_store',array('id'=>$_GPC['id'])); 
    $uid=pdo_get('users',array('username'=>$user['admin']));
    pdo_delete('users',array('username'=>$user['admin']));
    pdo_delete('uni_account_users',array('uid'=>$uid['uid']));
    pdo_delete('users_permission',array('uid'=>$uid['uid']));

	$res=pdo_delete('zh_yjm_store',array('id'=>$_GPC['id']));
	// var_dump($res);die;
	if($res){
	  message('删除成功',$this->createWebUrl('store',array()),'success');
	}else{
	  message('删除失败','','error');
	}
}
if($_GPC['op']=='hoty'){
	$res=pdo_update('zh_yjm_store',array('state'=>0),array('id'=>$_GPC['id']));
	if($res){
     message('', 'referer', 'success');
		// iajax('200','成功',$this->createWebUrl('activestore'), 'ajax', false);
    }else{
          message('失败！','','error');
    }
}
if($_GPC['op']=='hotx'){
	$res=pdo_update('zh_yjm_store',array('state'=>1),array('id'=>$_GPC['id']));
	if($res){
     message('', 'referer', 'success');
    }else{
          message('失败！','','error');
    }
}
include $this->template('web/store');